import request from '../utils/request.js';

export function getArticleList(pageNum, pageSize, params) {
  return request({
    url: '/sys/article/list/' + pageNum + '/' + pageSize + '',
    method: 'get',
    params
  });
}

export function getArticleListByType(typeId) {
  return request({
    url: '/sys/article/listByType/' + typeId,
    method: 'get',
  })
}

export function getArticleDetail(id) {
  return request({
    url: '/sys/article/'+id,
    method: 'get',
  })
}

export function getArticleContent(id) {
  return request({
    url: '/sys/article/content/'+id,
    method: 'get',
  })
}

export function addArticle(article) {
  return request({
    url: '/sys/article',
    method: 'post',
    data: article
  });
}

export function updateArticle(article) {
  return request({
    url: '/sys/article',
    method: 'put',
    data: article
  });
}

export function uploadFile(data) {
  return request({
    url: '/sys/article/upload',
    method: 'put',
    data: data,
    headers: { 'Content-Type': 'multipart/form-data'},
  });
}

export function deleteFile(fileName) {
  return request({
    url: '/sys/article/delFile',
    method: 'delete',
    params: {filename: fileName}
  })
}

export function deleteArticle(id) {
  return request({
    url: '/sys/article/'+id,
    method: 'delete',
  })
}

export function getAllTypeList() {
  return request({
    url: '/sys/article/type/listAll',
    method: 'get',
  })
}

export function addType(data) {
  return request({
    url: '/sys/article/type',
    method: 'post',
    data: data,
  })
}
